﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iOak.Common;
using System.Web.Security;
using iOak.Domain.Resumes;
using iOak.Business.Resumes;

namespace iOak.Web.Masters
{
    public partial class FrontEnd : BaseMasterPage
    {
        private WorkAssistant _workassistant = new WorkAssistant();

        public String DefaultPage
        {
            get
            {
                if (_workassistant.CurrentUser.IsAdmin)
                {
                    return "/Administration/Default.aspx";
                }
                else
                {
                    return "/Default.aspx";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (_workassistant.CurrentUser == null)
            {
                FormsAuthentication.RedirectToLoginPage();
            }

            if (!Page.IsPostBack)
            {
                lblUserName.Text = _workassistant.CurrentUser.FullName;
                CompanyService companyService = new CompanyService();
                Company company = companyService.Retrieve(_workassistant.CurrentUser.CompanyId);
                if (company != null)
                {
                    lblCompany.Text = company.CompanyName;
                }
                String currentPagePath = Request.Url.AbsolutePath;
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "setHoverMenu", "setHoverMenu('" + currentPagePath + "');", true);
            }
        }

        protected void lbtnLogout_Click(object sender, EventArgs e)
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
        }
    }
}